﻿function initTable() {
    $(".layui-table").find("[data-field='Status']").each(function () {
        var status = $(this).attr("data-content");
        if (status == 'R') {
            $(this).parent().attr("style", "background-color:red;color:white");
        }
        if (status == '2') {
            $(this).parent().attr("style", "background-color:#009688;color:white");
        }
    });
}

function initTableBtn(table) {
    //缓存当前操作的是哪个表格的哪个tr的哪个td
    $(document).off('mousedown', '.layui-table-grid-down').on('mousedown', '.layui-table-grid-down', function (event) {
        //直接记录td的jquery对象
        table._tableTrCurrr = $(this).closest('td');
    });

    //给弹出的详情里面的按钮添加监听级联的触发原始table的按钮的点击事件
    $(document).off('click', '.layui-table-tips-main [lay-event]').on('click', '.layui-table-tips-main [lay-event]', function (event) {
        var elem = $(this);
        var tableTrCurrr = table._tableTrCurrr;
        if (!tableTrCurrr) {
            return;
        }
        var layerIndex = elem.closest('.layui-table-tips').attr('times');
        layer.close(layerIndex);
        table._tableTrCurrr.find('[lay-event="' + elem.attr('lay-event') + '"]').first().click();
    });
}

function initForm(formId, data) {
    $.each(data, function (n, value) {
        if ($("#" + formId).find("[name='" + n + "']").attr("type") == "checkbox") {
            if (value == "1")
                $("#" + formId).find("[name='" + n + "']").attr("checked", "checked");
        }
        else if ($("#" + formId).find("[name='" + n + "']").attr("type") == "radio") {
            $("#" + formId).find("[name='" + n + "'][value='" + value + "']").attr("checked", "checked");
        }
        else {
            $("#" + formId).find("[name='" + n + "']").val(value);
        }
    });
};